import request from "@/utils/request";

// 获取用户列表
export const getUserListApi = (page, limit, searchParams) => {
  return request.get(`/admin/acl/user/${page}/${limit}`, {
    params: searchParams,
  });
};

/**
 * 添加或更新用户
 * @param user 用户对象
 * @returns null
 */
export const saveOrUpdateUserApi = (user) => {
  console.log(user);
  if (user.id) {
    console.log(user);
    return request.put('/admin/acl/user/update', user);
  }
  return request.post('/admin/acl/user/save', user);
};

/**
 * 获取用户角色列表
 * @param userId 用户id
 * @returns UserRoleListModel
 */
export const getUserRoleListApi = (userId) => {
  return request.get(`/admin/acl/user/toAssign/${userId}`);
};

/**
 * 给用户分配角色
 * @param userId 用户id
 * @param roleId 包含所有角色id的字符串 3,5,6
 * @returns
 */
export const assignUserRoleListApi = (userId, roleId) => {
  return request.post('/admin/acl/user/doAssign', null, {
    params: {
      userId,
      roleId,
    },
  });
};

/**
 * 删除用户
 * @param id 用户id
 * @returns null
 */
export const removeUserApi = (id) => {
  return request.delete(`/admin/acl/user/remove/${id}`);
};

/**
 * 批量删除多个用户
 * @param ids 多个用户id组成的数组
 * @returns
 */
export const removeUsersApi = (ids) => {
  return request.delete('/admin/acl/user/batchRemove', {data: ids,});
};
